/**
* cw
 */

package io.cw.controller.reservation;

import io.cw.common.utils.Result;
import io.cw.entity.background.ComplaintEntity;
import io.cw.entity.background.RoomEntity;
import io.cw.service.impl.background.ComplaintService;
import io.cw.service.impl.reservation.ReservationRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 预约抢座
 *
 * @author  cw
 */
@RestController
@RequestMapping("/reservation")
@Api(tags = "预约抢座", produces = MediaType.APPLICATION_JSON_VALUE)
public class ReservationController {


    @Autowired
    private ComplaintService complaintService;

    @Autowired
    private ReservationRecordService reservationRecordService;


    @PostMapping("/cancel/{seatId}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "座位ID", name = "seatId", required = true, paramType = "path", example = "1",dataTypeClass = String.class),
    })
    @ApiOperation("预约取消")
    public Result cancel(@PathVariable(value = "seatId") String seatId){
        reservationRecordService.cancel(seatId);
        return new Result<>().ok();
    }


    @PostMapping("/complaint/add")
    @ApiOperation("投诉登记")
    public Result addComplaint(@RequestBody @Valid ComplaintEntity addEntity){
        complaintService.add(addEntity);
        return new Result<>().ok();
    }


    @GetMapping("/room-time-seat/find")
    @ApiOperation("可预约列表")
    public Result<List<RoomEntity>> ableReservationList(){
        return new Result<List<RoomEntity>>().ok(reservationRecordService.ableReservationList());
    }

    @PostMapping("/submit/{seatId}/{phoneNumber}/{email}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "座位ID", name = "seatId", required = true, paramType = "path",dataTypeClass = String.class),
            @ApiImplicitParam(value = "手机号", name = "phoneNumber", required = true, paramType = "path",dataTypeClass = String.class),
            @ApiImplicitParam(value = "邮箱", name = "email", required = true, paramType = "path", dataTypeClass = String.class),
    })
    @ApiOperation("预约提交")
    public Result submit(@PathVariable(value = "seatId") String seatId, @PathVariable(value = "phoneNumber") String phoneNumber,
                         @PathVariable(value = "email") String email) throws Exception {
        reservationRecordService.submit(seatId, phoneNumber, email);
        return new Result<>().ok();
    }

}